<?php
/**
 * @fileoverview    封装我收到的评论显示模块数据
 * @author          gaojian3
 * @date            2012.02.14
 * @copyright       sina meila
 * @param           $aRows   评论数组
 * @return             $data
 */


class ml_biz_feed_commentMe extends ml_biz_feed_abstract{

    private $_uids;
    private $_pic_ids;
    private $_nicks;
    private $_personUrls;
    private $_personPics;
    private $_goodUrls;
    private $_pic_urls;
    private $oContent;
    private $oUserFeed;
    private $ordsCount;
    private $_cont_rids;


    public function __construct(){
        parent::__construct();
        $this->oContent=new ml_model_dbContent();
        $this->oUserFeed=new ml_model_dbUserfeed();
    }
    
    //回复的内容集合
    public function getReply($com_ids){
        
        if(!is_array($com_ids)){
            return array();
        }
        
        foreach($com_ids as $ids){
            $k=Tool_sina::calc_hash_tbl($ids['uid'],32);  //进哪些表
            $db_com[$k][$ids['com_id']]=$ids['uid'];
            $db_com[$k]['uid']=$ids['uid'];
        }
        
        $oComment =new ml_model_dbComment();
        foreach($db_com as $db){
            $uid=$db['uid'];
            unset($db['uid']);
            $idstr=implode(',',array_keys($db));
            $rs=$oComment->getCommentByComids($idstr,$uid);
            $data=$oComment->get_data();
            unset($db);
            foreach($data as $val){
                $com_rid=ml_tool_resid::make_resid($val['uid'],ML_RESID_TYPE_COMMENT,$val['com_id']);
                $comData[$com_rid]=$val;
            }
        }
        return $comData;
    }
    
    public function getComHtml($aRows){
        foreach($aRows as  &$val ){
            if(!empty($val['reply_id'])){
                $uid=ml_tool_resid::resid2uid($val['rid']);
                $comids[]=array(
                        'uid'=>    $uid,
                        'com_id' =>    $val['reply_id'],
                    );
            }
            if(ml_tool_resid::resid2type($val['rid']) == ML_RESID_TYPE_CONTENT)
            $this->_cont_rids[]=$val['rid'];
            if(ml_tool_resid::resid2type($val['rid']) == ML_RESID_TYPE_USERFEED){
                $feedRids[]=$val['rid'];
                if($val['content_rid']){
                    $this->_cont_rids[]=$val['content_rid'];
                }
            }
            unset($val);
            unset($uid);
        }
        
        $feedData=$this->oUserFeed->getUserfeedByRids($feedRids);
        foreach($feedData as $val){
            if($val['content_rid']){
                $this->_cont_rids[]=$val['content_rid'];
            }
        }
        $this->_cont_rids=array_unique($this->_cont_rids);
        $rids=array_merge($feedRids,$this->_cont_rids);
        $this->contData=$this->oContent->get_content_by_rids($this->_cont_rids);
        $feedData=$this->getFeedContent($feedData);
        $this->contData=$this->getContData($this->contData);
        $uid = $aRows[0]['uid'];
        $replyContent=$this->getReply($comids);
        
        foreach($aRows as $val){
            $tmp['vuid']=$val['uid'];
            $tmp['uid']=$val['act_uid'];
            $tmp['feed_rid']=$val['rid'];
            $tmp['content']=ml_tool_formatContent::format_content($val['content']);
            $tmp['from']=$val['from'];
            $tmp['ctime']=$val['ctime'];
            $tmp['rid']=$val['content_rid'];
            $tmp['com_id']=$val['com_id'];
            $tmp['reply_id'] =$val['reply_id'];
            $tmp['show_type']='quote';
            $tmp['show_share']=false;
            $tmp['show_com']=true;
            $tmp['show_com_cnt']=false;
            if(!empty($val['reply_id'])){
                $com_rid=ml_tool_resid::make_resid(ml_tool_resid::resid2uid($val['rid']),ML_RESID_TYPE_COMMENT,$val['reply_id']);
                $tmp['reply']=$replyContent[$com_rid] ;
                $tmp['reply']['content'] = ml_tool_formatContent::format_content($tmp['reply']['content']);
            }
            if(empty($tmp['rid'])){//feed
                $tmp['res'] = $feedData[$tmp['feed_rid']];
                $tmp['rid'] = $tmp['feed_rid'];
            }else{
                $tmp['res'] = $this->contData[$tmp['rid']];
            }
            $tmp['show_del']= in_array($uid,array($tmp['uid'],$tmp['res']['uid']))? true:false;
            $arrData[]=$tmp;
            unset($val);unset($tmp);
        }
        return $this->parse($arrData);
    }

    public function getFeedContent(&$feedData){
        foreach($feedData as &$val){
            $val['content']=ml_tool_formatContent::format_content($val['content']);
            switch($val['type']){
                case ML_FEED_TYPE_MOD_DEC:
                    $val['content'] = $this->formate_dec_content($val['content']);
                    break;
                case ML_FEED_TYPE_ATTITUDE:
                    $val['content'] = $this->formate_att_content($val['feed_info']['attitude']);
                    break;
                case ML_FEED_TYPE_MOD_TAG:
                    $val['content']=$this->formate_tag_content($val['content']);
                    break;
                case ML_FEED_TYPE_REPOST_COLLECTION:
                    $val['content'] = $this->format_collect_content($val);
                    break;
            }

            unset($val);
        }
        return $feedData;
    }

    public function getContData(&$contData){

        return $contData;
    }

}







